<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateTableIntegral extends Migrator
{
    public function up()
    {
        if (!$this->hasTable('integral')) {
            $table = $this->table('integral', ['engine' => 'MyISAM'])
                ->setId('id')
                ->setPrimaryKey('id')
                ->setComment('积分表');
            $table->addColumn('group_id', 'string', ['limit' => 100, 'null' => false, 'comment' => '群id'])
                ->addColumn('uid', 'string', ['limit' => 100, 'null' => false, 'default' => '', 'comment' => '群成员id'])
                ->addColumn('sum_num', 'integer', ['limit' => 11, 'null' => false, 'default' => '0', 'comment' => '总积分'])
                ->addColumn('num', 'integer', ['limit' => 11, 'null' => false, 'default' => '0', 'comment' => '可用积分'])
                ->addIndex(['group_id','uid'])
                ->create();
        }
    }

    public function down()
    {
        if ($this->hasTable('integral')) {
            $this->dropTable('integral');
        }
    }
}
